package com.example.blog.Schedule;


import com.example.blog.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @Author: lu
 * @Date: 2023-11-23-11:21
 * @Description: 定时任务
 */
@Component
@Slf4j
public class ScheduleTask {
    private  static  int count = 0;

    @Autowired
    RedisUtil redisUtil;

    @Scheduled(cron = "0 0 0 * * *")
    public  void task(){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info(simpleDateFormat.format(date)+": scheduled");

        ArrayList<Object> list = new ArrayList<>();

        count++;
        list.add(count);
        redisUtil.set("count",list);

    }

}
